package assetservicelogic

import (
	"context"
	"property_service/dao/model"
	"property_service/dao/query"
	"property_service/utils/BeanUtils"

	"property_service/internal/svc"
	"property_service/property_service"

	"github.com/zeromicro/go-zero/core/logx"
)

type AssetBasicInfoByIdsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAssetBasicInfoByIdsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AssetBasicInfoByIdsLogic {
	return &AssetBasicInfoByIdsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 通过id集合查询指定资产信息
func (l *AssetBasicInfoByIdsLogic) AssetBasicInfoByIds(in *property_service.AssetBasicInfoByIdsReq) (*property_service.AssetBasicInfoPageRes, error) {
	// 定义一个资产信息表模型对象切片用于存储查询结果
	var data []*model.AssetBasicInfo
	// 获取资产信息表模型的查询构造器
	m := query.Use(l.svcCtx.Gorm).AssetBasicInfo
	// 根据传入的id集合查询资产信息
	do := m.WithContext(l.ctx).Where(m.ID.In(in.Ids...))
	// 定义一个变量用于存储总记录数
	var count int64
	// 如果不需要分页，查询所有记录
	data, _ = do.Find()
	// 设置总记录数为查询结果的长度
	count = int64(len(data))
	// 将查询结果转换为响应对象
	list, _ := BeanUtils.CopyProperties(data, property_service.AssetBasicInfo{})

	// 返回查询结果，包括总记录数和数据列表
	return &property_service.AssetBasicInfoPageRes{
		Count: count,
		List:  list.([]*property_service.AssetBasicInfo),
	}, nil
}
